package org.example.springoauth2.securitycommon.util;

import lombok.experimental.UtilityClass;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hzq
 * @date 2021/10/11 10:28
 */
@UtilityClass
public class RequestUtil {

    public HttpServletRequest getHttpServletRequest() {
        return getServletRequestAttributes().getRequest();
    }

    public HttpServletResponse getHttpServletResponse() {
        return getServletRequestAttributes().getResponse();
    }

    public ServletRequestAttributes getServletRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    }
}
